package cn.hznc.controller.process;

import cn.hznc.aspect.BusinessType;
import cn.hznc.aspect.Log;
import cn.hznc.controller.service.process.EmployeeService;
import cn.hznc.domain.entity.ProcessEntity;
import cn.hznc.domain.request.process.AddOrEditEmployeeReq;
import cn.hznc.domain.request.process.QueryProcessReq;
import cn.hznc.domain.response.PageResult;
import cn.hznc.domain.response.ResponseBody;
import cn.hznc.exception.ToolManageException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：Administrator
 * @Date：2023/6/7 23:33
 */
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;


    @RequestMapping(value = "/addOrEditEmployee", method = RequestMethod.POST)
    @Log(title = "新增或编辑人员" , businessType = BusinessType.OTHER)
    public ResponseBody addOrEditEmployee(@RequestBody AddOrEditEmployeeReq addOrEditEmployeeReq) {
        try {
            return ResponseBody.success(employeeService.addOrEditEmployee(addOrEditEmployeeReq));
        } catch (ToolManageException e) {
            return ResponseBody.error(e.getCode(),e.getMessage());
        }
    }

    @RequestMapping(value = "/deleteEmployee", method = RequestMethod.GET)
    @Log(title = "删除人员" , businessType = BusinessType.DELETE)
    public ResponseBody deleteEmployee(@RequestParam("id") Integer id) {
            return ResponseBody.success(employeeService.deleteEmployee(id));
    }

    @RequestMapping(value = "/selectEmployees", method = RequestMethod.GET)
    public ResponseBody selectEmployees() {
        return ResponseBody.success(employeeService.selectEmployees());
    }
}
